#ifndef _DLIST_H_
#define _DLIST_H_


#include <stdlib.h>

typedef struct dlist_node {
	void 				*data;
	struct dlist_node	*prev;
	struct dlist_node	*next;
}dlist_node_t;


typedef struct dlist {
	int					size;
	int					(*match)(const void *key1, const void *key2);
	void				(*destroy)(void *data);
	dlist_node_t		*head;
	dlist_node_t		*tail;
}dlist_t;


void dlist_init(dlist_t *dlist, void (*destroy)(void *data));
void dlist_destroy(dlist_t *dlist);
int dlist_insert_next(dlist_t *dlist, dlist_node_t *l, const void *data);
int dlist_insert_prev(dlist_t *dlist, dlist_node_t *l, const void *data);
int dlist_remove(dlist_t *dlist, dlist_node_t *l, void **data);


#define dlist_size(dlist)		((dlist)->size)
#define dlist_head(dlist)		((dlist)->head)
#define dlist_tail(dlist)		((dlist)->tail)
#define dlist_data(n)			((n)->data)
#define dlist_prev(n)			((n)->prev)
#define dlist_next(n)			((n)->next)

#define dlist_is_head(n)		((n)->prev == NULL ? 1 : 0)
#define dlist_is_tail(n)		((n)->next == NULL ? 1 : 0)






#endif /*_DLIST_H_*/

